<!DOCTYPE html>
<html>
<head>
    <title>{$node.node_title}</title>
    {include file="common/header"/}
    <el-card class="box-card" shadow="never">
        <el-tabs v-model="activeName">
            <el-tab-pane :label="item.name" :name="item.val" v-for="(item, index) in tabname" :key="index" v-if="item.show">
                <div class="base_form" style="padding-right: 220px;">
                    <el-form ref="form" label-width="220px">
                        <block v-for="(items, indexs) in form" :key="indexs">
                            <el-form-item :label="items.conf_title?items.conf_title:items.conf_key" v-if="items.conf_type==item.val">
                                <block v-if="items.conf_spec==1">
                                    <el-input type="textarea" :rows="4" v-model="items.conf_value"></el-input>
                                </block>
                                <block v-else-if="items.conf_spec==2">
                                    <el-radio v-model="items.conf_value" v-for="(val, key) in items.conf_content" :key="key" :label="val.value">{{val.name}}</el-radio>
                                </block>
                                <block v-else-if="items.conf_spec==3">
                                    <el-checkbox-group v-model="items.conf_value">
                                        <el-checkbox v-for="(val, key) in items.conf_content" :key="key" :label="val.value">{{val.name}}</el-checkbox>
                                    </el-checkbox-group>
                                </block>
                                <block v-else-if="items.conf_spec==4">
                                    <Single v-model="items.conf_value"/>
                                </block>
                                <block v-else-if="items.conf_spec==5">
                                    <Single v-model="items.conf_value" multiple="true" :selected_num="items.conf_value.length"/>
                                </block>
                                <block v-else-if="items.conf_spec==6">
                                    <Ueditor v-model="items.conf_value"></Ueditor>
                                </block>
                                <block v-else-if="items.conf_spec==7">
                                    <el-color-picker v-model="items.conf_value"></el-color-picker>
                                </block>
                                <block v-else>
                                    <el-input v-model="items.conf_value"></el-input>
                                </block>
                                <span class="f_tips">{{items.conf_desc}}<span v-if="items.conf_spec==5">　最多上传10张</span></span>
                            </el-form-item>
                        </block>
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit(item.val)">保存配置</el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </el-tab-pane>
        </el-tabs>
        
    </el-card>
    {include file="common/footer"/}
    <script>
        var app = new Vue({
            el: '#app',
            data() {
                this.getData();
                return {
                    form: [],
                    activeName: "0",
                    tabname: [
                        {
                            name: '基础设置',
                            val: '0',
                            show: false,
                        },
                        {
                            name: 'SEO设置',
                            val: '9',
                            show: false,
                        },
                        {
                            name: '前端模版',
                            val: '3',
                            show: false,
                        },
                        {
                            name: '搜索设置',
                            val: '1',
                            show: false,
                        },
                        {
                            name: '微信设置',
                            val: '8',
                            show: false,
                        },
                        {
                            name: '交易设置',
                            val: '10',
                            show: false,
                        },
                        {
                            name: '售后设置',
                            val: '11',
                            show: false,
                        },
                        {
                            name: '上传配置',
                            val: '2',
                            show: false,
                        },
                        {
                            name: '其他配置',
                            val: '4',
                            show: false,
                        },
                    ],
                }
            },
            methods: {
                getData() {
                    var that = this;
                    axios.post('/admin/conf/getBaseConfig', Object.assign({}, PostBase))
                        .then(function (res) {
                            if (res.data.code == 200) {
                                for (let item of res.data.data) {
                                    if (item.conf_spec == 2) {
                                        for (let i = 0; i < item.conf_content.length; i++) {
                                            let d = item.conf_content[i].split("=>");
                                            item.conf_content[i] = {
                                                name: d[0].toString(),
                                                value: d[1].toString()
                                            }
                                        }
                                    }else if(item.conf_spec==3){
                                        for (let i = 0; i < item.conf_content.length; i++) {
                                            let d = item.conf_content[i].split("=>");
                                            item.conf_content[i] = {
                                                name: d[0].toString(),
                                                value: d[1].toString()
                                            }
                                        }
                                        if(item.conf_value){
                                            item.conf_value = item.conf_value.split(",");
                                        }else{
                                            item.conf_value = []
                                        }
                                    }else if (item.conf_spec == 5) {
                                        if(item.conf_value){
                                            item.conf_value = item.conf_value.split(",");
                                            for (let i = 0; i < item.conf_value.length; i++) {
                                                if (!item.conf_value[i]) {
                                                    item.conf_value.splice(i, 1);
                                                }
                                            }
                                        } else {
                                            item.conf_value = []
                                        }
                                    }
                                    for (let i = 0; i < that.tabname.length; i++) {
                                        if(that.tabname[i].val == item.conf_type){
                                            that.tabname[i].show = true
                                        }
                                    }
                                }
                                that.form = res.data.data;
                            } else {
                                that.$message.error(res.data.message);
                            }
                        })
                        .catch(function (error) {
                            that.$message.error('服务器内部错误');
                            console.log(error);
                        });
                },
                onSubmit(index) {
                    var that = this;
                    var postData = {};
                    for (var i = 0; i < that.form.length; i++) {
                        if(that.form[i].conf_type == index){
                            postData[that.form[i].conf_key] = that.form[i].conf_value;
                        }
                    }
                    axios.post('/admin/conf/updateBaseConfig', Object.assign({}, PostBase, postData))
                        .then(function (res) {
                            if (res.data.code == 200) {
                                that.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {
                                that.$message.error(res.data.message);
                            }
                        })
                        .catch(function (error) {
                            that.$message.error('服务器内部错误');
                            console.log(error);
                        });
                },
            }
        })
    </script>


</html>